"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fisherYates_1 = __importDefault(require("./fisherYates"));
class Shuffle {
    constructor() {
        this.cards = [];
        this.length = 0;
        // 从上到下抽牌
        this.draw = (num) => {
            if (!num || num <= 1) {
                this.length = this.cards.length - 1;
                return this.cards.pop();
            }
            const ret = [];
            const len = Math.min(num, this.cards.length);
            for (let i = 0; i < len; i++) {
                ret.push(this.cards.pop());
                this.length = this.cards.length;
            }
            return ret;
        };
        // this.reset();
        this.cards = Array.from({ length: 54 }, (_, i) => i + 1);
        this.shuffle();
    }
    // 重置
    reset() {
        this.cards = this.cards.slice(0);
        this.length = this.cards.length;
    }
    // 洗牌
    shuffle() {
        (0, fisherYates_1.default)(this.cards);
    }
    // 发牌
    deal(numberOfCards, arrayOfHands) {
        for (let i = 0; i < numberOfCards; i++) {
            for (let j = 0; j < arrayOfHands.length; j++) {
                const card = this.cards.pop();
                if (card)
                    arrayOfHands[j].push(card);
            }
        }
        this.length = this.cards.length;
    }
    drawFromBottomOfDeck(num) {
        if (!num || num < 1) {
            num = 1;
        }
        const ret = [];
        for (let i = 0; i < num; i++) {
            ret.push(this.cards.shift());
        }
        this.length = this.cards.length;
        if (ret.length === 1) {
            return ret[0];
        }
        else {
            return ret;
        }
    }
    // 随机抽牌
    drawRandom(num) {
        const _draw = () => {
            const index = Math.floor(Math.random() * this.cards.length);
            const card = this.cards[index];
            this.cards.splice(index, 1);
            this.length = this.cards.length;
            return card;
        };
        if (!num || num <= 1) {
            return _draw.apply(this);
        }
        else {
            var cards = [];
            for (var i = 0; i < num; i++) {
                cards.push(_draw.apply(this));
            }
            return cards;
        }
    }
    // 添加牌
    putOnTopOfDeck(cards) {
        this.cards = [...this.cards, ...cards];
        this.length = this.cards.length;
    }
    putOnBottomOfDeck(cards) {
        this.cards = [...cards, ...this.cards];
        this.length = this.cards.length;
    }
}
exports.default = Shuffle;
